package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-08-30
 * Time: 17:28
 */
public class Demo4 {
    public static boolean isQuit = false;

    //直接使用自己的标志位来区分线程是否要结束
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while(!isQuit){
                System.out.println("线程运行中...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("线程执行结束");
        });
        thread.start();
        Thread.sleep(5000);
        isQuit = true;
    }
}
